use tokio::{
    select,
    signal::unix::{signal, Signal, SignalKind},
};

pub struct SignalManager {
    sig_term: Signal,
    sig_quit: Signal,

    pub terminate: bool,
    pub quit: bool,
}

impl SignalManager {
    pub fn new() -> Self {
        let sig_term = signal(SignalKind::terminate()).unwrap();
        let sig_quit = signal(SignalKind::quit()).unwrap();
        SignalManager {
            sig_term,
            sig_quit,
            terminate: false,
            quit: false,
        }
    }

    pub async fn recv(&mut self) {
        select! {
            _ = self.sig_term.recv() => {
                self.terminate = true;
            }

            _ = self.sig_quit.recv() => {
                self.quit = true;
            }
        }
    }
}
